package com.spring.boot.utils;

/**
 * String 工具类
 */
public class StringUtils {


    /**
     * 校验标记是否存在第一个字符
     */
    public static boolean startsWithChar(String path, char sign) {

        if (path.length() == 0) {
            return false;
        } else {
            return path.charAt(0) == sign;
        }
    }


    public static int indexOf(String str,char sign){
        return indexOf(str,sign,0,str.length());
    }

    /**
     *
     */
    public static int indexOf(String path, char sign, int startIndex, int endIndex) {
        if (startIndex < 0) {
            startIndex = 0;
        }

        int pathLen = path.length();
        if (endIndex > pathLen) {
            endIndex = pathLen;
        }

        for (int i = startIndex; i < endIndex; i++) {
            if (path.charAt(i) == sign) {
                return i;
            }
        }

        return -1;
    }


    public static int indexOfChars(String str, char[] indexChars) {
        return indexOfChars(str, indexChars, 0);
    }

    public static int indexOfChars(String str, char[] indexChars, int startIndex) {

        int strLen = str.length();
        int charsLen = indexChars.length;

        for (int i = startIndex; i < strLen; i++) {
            char c = str.charAt(i);
            for (int j = 0; j < charsLen; j++) {
                if (c == indexChars[j]) {
                    return i;
                }
            }
        }
        return -1;
    }
}
